<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-form-item prop="key">
          <el-input v-model="filters.key" placeholder="名称"></el-input>
        </el-form-item>
        <el-form-item prop="type">
          <el-input v-model="filters.type" placeholder="类型"></el-input>
        </el-form-item>
        <el-form-item prop="queryname">
          <el-input v-model="filters.queryname" placeholder="备注"></el-input>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button
              icon="fa fa-plus"
              :label="$t('action.add')"
              type="primary"
              @click="handleAdd"
            />
          </el-form-item>
          <el-form-item>
            <kt-button :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      @findPage="findPage"
      @handleEdit="handleEdit"
      @handleDelete="handleDelete"
      ref="CyTable"
    ></cy-table>
    <!--新增编辑界面-->
    <el-dialog
      :title="operation?'新增':'编辑'"
      width="40%"
      :visible.sync="editDialogVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :model="dataForm"
        label-width="80px"
        :rules="dataFormRules"
        ref="dataForm"
        :size="size"
      >
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataForm.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="申请金额" prop="apply_num">
          <el-input v-model="dataForm.apply_num" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="放款方式" prop="apply_type">
          <el-select v-model="dataForm.apply_type" style="width:100%">
               <el-option label="支付宝" value="支付宝"></el-option> 
               <el-option label="微信" value="微信"></el-option> 
               <el-option label="银行卡" value="银行卡"></el-option> 
          </el-select>
        </el-form-item>
        <el-form-item label="收款人姓名" prop="reciever">
          <el-input v-model="dataForm.reciever" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="收款账号" prop="recievea_ccount">
          <el-input v-model="dataForm.recievea_ccount" auto-complete="off" ></el-input>
        </el-form-item>
         <el-form-item label="申请日期" prop="apply_time">
           <el-date-picker
          v-model="dataForm.apply_time" value-format="yyyy-MM-dd"
          type="date"
          >
        </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="status_alias">
           <el-select v-model="dataForm.status_alias" style="width:100%">
               <el-option label="全部" value=""></el-option> 
               <el-option label="待审核" value="120"></el-option>
               <el-option label="审核通过" value="121"></el-option>  
               <el-option label="放款中" value="122"></el-option> 
               <el-option label="提现成功" value="123"></el-option> 
               <el-option label="审核拒绝" value="124"></el-option> 
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="editDialogVisible = false">{{$t('action.cancel')}}</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="submitForm"
          :loading="editLoading"
        >{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      filters: {
        key: "",
        type: "",
        t: "applyCash",
        queryname: ""
      },
      columns: [
        { prop: "id", label: "ID", minWidth: 50 },
        { prop: "", label: "所属门店", minWidth: 100 },
        { prop: "", label: "申请人", minWidth: 100 },
        { prop: "apply_num", label: "申请金额", minWidth: 80 },
        { prop: "apply_type", label: "放款方式", minWidth: 120 },
        { prop: "reciever", label: "收款人姓名", minWidth: 80 },
        { prop: "recievea_ccount", label: "收款人账号", minWidth: 80 },
        { prop: "apply_time", label: "申请时间", minWidth: 80 },
        { prop: "status_alias", label: "状态", minWidth: 100 }
	  ],
	  filterColumns:[],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},

      operation: false, // true:新增, false:编辑
      editDialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,
      dataFormRules: {
        apply_num: [{ required: true, message: "请输入申请金额", trigger: "blur" }],
        reciever: [{ required: true, message: "请输入收款人姓名", trigger: "blur" }],
        recievea_ccount: [{ required: true, message: "请输入收款人账号", trigger: "blur" }]
      },
      // 新增编辑界面数据
      dataForm: {
        id: "",
        key: "",
        val: "",
        type: "",
        remark: ""
      }
    };
  },
  methods: {
    // 获取分页数据
    findPage: function(data) {
      this.$refs.CyTable.findPage(this.filters);
    },
    // 批量删除
    handleDelete: function(data) {
      if (data != null && data.params != null && data.params.length > 0) {
        let ids = data.params.map(item => item.id).toString();

        var params = {};
        params.t = "sysConfig";
        params.ids = ids;
        var this_ = this;
        this.utils.request.deleteUserInfo(params, function(res) {
          if (res.code == "0000") {
            this_.$message({ message: "操作成功", type: "success" });
            this_.findPage(null);
          } else {
            this_.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        });
      }
    },
    // 显示新增界面
    handleAdd: function() {
      this.editDialogVisible = true;
      this.operation = true;
      this.resetForm("dataForm");
    },
    // 显示编辑界面
    handleEdit: function(params) {
      this.editDialogVisible = true;
      this.operation = false;
      this.$nextTick(function() {
        this.dataForm = Object.assign({}, params.row);
      });
    },
    // 编辑
    submitForm: function() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {}).then(() => {
            let params = Object.assign({}, this.dataForm);

            params.t = "sysConfig";
            var this_ = this;
            this.utils.request.editInfo(params, function(res) {
              if (res.code == "0000") {
                this_.$message({ message: "操作成功", type: "success" });

                this_.$refs["dataForm"].resetFields();

                this_.editDialogVisible = false;

                this_.findPage(null);
              } else {
                this_.$message({
                  message: "操作失败, " + res.msg,
                  type: "error"
                });
              }
            });
          });
        }
      });
    },

    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },

    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      var temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "系统参数下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },
  mounted() {
	  this.initColumns()
  }
};
</script>

<style scoped>
</style>